const config = require('./dink/js/config')
const helper = require('./dink/js/helper')
const http = require('./dink/js/http')

App({
  onLaunch: async function () {
    wx.loadFontFace({
      global: true,
      family: 'st',
      source: 'https://sys.zhibenguyi.com//res/font/STSONG.TTF',
      // success: console.log,
      fail: console.log
    })
    // 窗口背景色
    wx.setBackgroundColor({
      // backgroundColorTop: config.theme, // 顶部窗口的背景色为白色
      backgroundColorTop: '#ffffff', // 顶部窗口的背景色为白色
      backgroundColorBottom: '#ffffff', // 底部窗口的背景色为白色
    })
    // nav-bar
    const { statusBarHeight, platform } = wx.getSystemInfoSync()
    const { top, height } = wx.getMenuButtonBoundingClientRect()
    wx.setStorageSync('statusBarHeight', statusBarHeight)
    wx.setStorageSync('menuButtonTop', top ? top : 24)
    wx.setStorageSync('menuButtonHeight', height ? height : 32)
    let navigationBarHeight
    if (top && top !== 0 && height && height !== 0) {
      navigationBarHeight = (top - statusBarHeight) * 2 + height + 4
    } else {
      navigationBarHeight = platform === 'android' ? 52 : 44
    }
    wx.setStorageSync('navigationBarHeight', navigationBarHeight)
    wx.setStorageSync('navigationBarAndStatusBarHeight', statusBarHeight + navigationBarHeight)
    // 获取openId
    const userInfo = await this.helper.getUserInfo('/wxa/user/login')
    this.globalData.userInfo = userInfo || null
  },
  globalData: {
    userInfo: null,
    index: 'pages/index/index',
    chooseBtn: false,
    theme: config.theme
  },
  helper: helper,
  http: http,
  config: config
})